import Vue from 'vue';
import './cube-ui';
import App from './App.vue';
import router from './router';
import store from './store/index';
import './wechat-title';
// import './registerServiceWorker';
import './inobounce';
import './viewportUnitsBuggyfill';
import './fast-click';


Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
    if (to.meta.loginAuth) {  // 判断该路由是否需要登录权限
        const storeState: any = store.state;
        if (storeState.UserStore.UserId && storeState.UserStore.Token) {  // 通过vuex state获取当前的token是否存在
            next();
        } else {
            next({
                path: '/login',
                query: {redirect: to.fullPath},
            });
        }
    } else {
        next();
    }
});

router.afterEach((to, from) => {
    if (process.env.NODE_ENV !== 'development') {
        require('viewport-units-buggyfill').refresh();
    }
});
setTimeout(() => {
    new Vue({
        router,
        store,
        render: (h) => h(App),
    }).$mount('#app');
}, 500);

document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    (window as any).StatusBar.show();
    (window as any).StatusBar.overlaysWebView(false);
    (window as any).StatusBar.overlaysWebView(true);
}


